package admin

import (
	"invitation/internal/application"
	"invitation/internal/pojo/vo"

	"github.com/gofiber/fiber/v2"
)

func TeacherListAllEndpoint(application *application.Application) func(ctx *fiber.Ctx) error {
	return func(ctx *fiber.Ctx) error {
		teacherInfos, err := application.RepoManager().FirstTimeTeacherInfoRepo().FindListAll()
		if err != nil {
			return ctx.Status(500).JSON(fiber.Map{
				"message": err.Error(),
			})
		}
		var dataToReturn []vo.FirstTimeTeacher
		for _, teacherInfo := range teacherInfos {
			postport, err := application.RepoManager().FirstTimePostportRepo().FindOneByTeacherInfoID(teacherInfo.ID)
			if err != nil {
				return ctx.Status(500).JSON(fiber.Map{
					"message": err.Error(),
				})
			}
			dataToReturn = append(dataToReturn, vo.FirstTimeTeacher{
				FirstTimeTeacherInfo: teacherInfo,
				PostportUrl:          postport.PostportUrl,
			})
		}
		return ctx.Status(200).JSON(dataToReturn)
	}
}
